#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string optimalDivision(vector<int>& nums) {
        string ret;
        int n = nums.size();
        ret += to_string(nums[0]);
        if (n == 1) return ret;
        ret += "/";
        if (n == 2)
        {
            ret += to_string(nums[1]);
            return ret;
        }
        ret += "(";
        for (int i = 1; i < n - 1; i++) ret += to_string(nums[i]) + "/";
        ret += to_string(nums[n - 1]) + ")";
        return ret;
    }
};